package IO;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

public class IO1 {
    public static void main1(String[] args) throws IOException {
        File file = new File("D:\\JavaEE\\text.txt");
        System.out.println(file.getParent());
        System.out.println(file.getName());
        System.out.println(file.getPath());
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getCanonicalPath());
    }

    public static void main2(String[] args) throws IOException {
        File file = new File("./text.txt");
        System.out.println(file.getParent());
        System.out.println(file.getName());
        System.out.println(file.getPath());
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getCanonicalPath());
    }
    /**
     * 输出
     * .
     * text.txt
     * .\text.txt
     * D:\LXY_Java\javaa\Thread\.\text.txt
     * D:\LXY_Java\javaa\Thread\text.txt
     */
    public static void main(String[] args) throws IOException {
        try (InputStream is = new FileInputStream("test.txt")) {
            try (Scanner scanner = new Scanner(is, "UTF-8")) {
                while (scanner.hasNext()) {
                    String s = scanner.next();
                    System.out.print(s);
                }
            }
        }
    }
}
